package constant.milk.periodapp.setting;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import constant.milk.periodapp.R;
import constant.milk.periodapp.SuperActivity;
import constant.milk.periodapp.dialog.MilkColorLineDialog;
import constant.milk.periodapp.dialog.MilkColorLineDialog.ColorLineCallBack;
import constant.milk.periodapp.dialog.MilkColorSelectDialog;
import constant.milk.periodapp.dialog.MilkColorSelectDialog.ColorSelectCallBack;
import constant.milk.periodapp.util.MilkShared;
import constant.milk.periodapp.util.MilkUtil;

public class ColorActivity extends SuperActivity
{
	private TextView backTextView;
	
	private View todayView;
	private View calendarView;
	private View weekdayView;
	
	private TextView todayTextView, sunday, monday, tuesday, wednesday, thursday, friday, saturday;
	
	private View sengriView;
	private View gaimView;
	private View beranView;
	private View sexView;
	private View memoView;
	
	private TextView sengriTextView;
	private TextView gaimTextView;
	private TextView beranTextView;
	private TextView sexTextView;
	private TextView memoTextView;
	
	private TextView resetTextView;
	
	private MilkColorSelectDialog colorSelectDialog;
	private MilkColorLineDialog colorLineDialog;
	
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.color_activity);
		
		setFindViewId();
		setOnClick();
		setData();
	}

	@Override
	protected void setFindViewId()
	{
		backTextView = (TextView) findViewById(R.id.colorBackTextView);
		
		todayView = findViewById(R.id.colorTodayView);
		todayTextView = (TextView) findViewById(R.id.colorTodayTextView);
		
		calendarView = findViewById(R.id.colorCalendarView);
		weekdayView = findViewById(R.id.colorCalendarWeekdayView);
		sunday = (TextView) findViewById(R.id.colorCalendarSunday);
		monday = (TextView) findViewById(R.id.colorCalendarMonday);
		tuesday = (TextView) findViewById(R.id.colorCalendarTuesday);
		wednesday = (TextView) findViewById(R.id.colorCalendarWednesday);
		thursday = (TextView) findViewById(R.id.colorCalendarThursday);
		friday = (TextView) findViewById(R.id.colorCalendarFriday);
		saturday = (TextView) findViewById(R.id.colorCalendarSaturday);
		
		sengriView = findViewById(R.id.colorSengriView);
		gaimView = findViewById(R.id.colorGaimView);
		beranView = findViewById(R.id.colorBeranView);
		sexView = findViewById(R.id.colorSexView);
		memoView = findViewById(R.id.colorMemoView);
		
		sengriTextView = (TextView) findViewById(R.id.colorSengriTextView);
		gaimTextView = (TextView) findViewById(R.id.colorGaimTextView);
		beranTextView = (TextView) findViewById(R.id.colorBeranTextView);
		sexTextView = (TextView) findViewById(R.id.colorSexTextView);
		memoTextView = (TextView) findViewById(R.id.colorMemoTextView);
		
		resetTextView = (TextView) findViewById(R.id.colorResetTextView);
	}

	@Override
	protected void setOnClick()
	{
		backTextView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				finish();
			}
		});
		
		todayView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				colorLineDialog = new MilkColorLineDialog(superContext, new ColorLineCallBack()
				{
					@Override
					public void getColor(String color)
					{
						MilkShared ms = new MilkShared(superContext);
						ms.setColorToday(color);
						MilkUtil.showToast(superContext, "오늘 날짜 색 변경에 성공하였습니다.");
						setData();
						setResult(Activity.RESULT_OK);
					}
				});
				
				colorLineDialog.show();
			}
		});
		
		calendarView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				colorLineDialog = new MilkColorLineDialog(superContext, new ColorLineCallBack()
				{
					@Override
					public void getColor(String color)
					{
						MilkShared ms = new MilkShared(superContext);
						ms.setColorLine(color);
						MilkUtil.showToast(superContext, "달력 선 색 변경에 성공하였습니다.");
						setData();
						setResult(Activity.RESULT_OK);
					}
				});
				
				colorLineDialog.show();
			}
		});
		
		sengriView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				colorSelectDialog = new MilkColorSelectDialog(superContext, new ColorSelectCallBack()
				{
					@Override
					public void getColor(String color)
					{
						MilkShared ms = new MilkShared(superContext);
						ms.setColorSengri(color);
						MilkUtil.showToast(superContext, "생리일 색 변경에 성공하였습니다.");
						setData();
						setResult(Activity.RESULT_OK);
					}
				});
				
				colorSelectDialog.show();
			}
		});
		
		gaimView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				colorSelectDialog = new MilkColorSelectDialog(superContext, new ColorSelectCallBack()
				{
					@Override
					public void getColor(String color)
					{
						MilkShared ms = new MilkShared(superContext);
						ms.setColorGaim(color);
						MilkUtil.showToast(superContext, "가임일 색 변경에 성공하였습니다.");
						setData();
						setResult(Activity.RESULT_OK);
					}
				});
				
				colorSelectDialog.show();
			}
		});
		
		beranView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				colorSelectDialog = new MilkColorSelectDialog(superContext, new ColorSelectCallBack()
				{
					@Override
					public void getColor(String color)
					{
						MilkShared ms = new MilkShared(superContext);
						ms.setColorBeran(color);
						MilkUtil.showToast(superContext, "배란일 색 변경에 성공하였습니다.");
						setData();
						setResult(Activity.RESULT_OK);
					}
				});
				
				colorSelectDialog.show();
			}
		});
		
		sexView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				colorSelectDialog = new MilkColorSelectDialog(superContext, new ColorSelectCallBack()
				{
					@Override
					public void getColor(String color)
					{
						MilkShared ms = new MilkShared(superContext);
						ms.setColorSex(color);
						MilkUtil.showToast(superContext, "관계일 색 변경에 성공하였습니다.");
						setData();
						setResult(Activity.RESULT_OK);
					}
				});
				
				colorSelectDialog.show();
			}
		});
		
		memoView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				colorSelectDialog = new MilkColorSelectDialog(superContext, new ColorSelectCallBack()
				{
					@Override
					public void getColor(String color)
					{
						MilkShared ms = new MilkShared(superContext);
						ms.setColorMemo(color);
						MilkUtil.showToast(superContext, "메모 색 변경에 성공하였습니다.");
						setData();
						setResult(Activity.RESULT_OK);
					}
				});
				
				colorSelectDialog.show();
			}
		});
		
		resetTextView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				MilkShared ms = new MilkShared(superContext);
				ms.removeColor();
				MilkUtil.showToast(superContext, "전체색을 기본 값으로 되돌렸습니다.");
				setData();
				setResult(Activity.RESULT_OK);
			}
		});
	}

	@Override
	protected void setData()
	{
		MilkShared ms = new MilkShared(superContext);
		
		todayTextView.setBackgroundColor(Color.parseColor(ms.getColorToday()));
		
		weekdayView.setBackgroundColor(Color.parseColor(ms.getColorLine()));
		sunday.setTextColor(Color.RED);
		monday.setTextColor(Color.parseColor(MilkUtil.getTextColorLine(ms.getColorLine())));
		tuesday.setTextColor(Color.parseColor(MilkUtil.getTextColorLine(ms.getColorLine())));
		wednesday.setTextColor(Color.parseColor(MilkUtil.getTextColorLine(ms.getColorLine())));
		thursday.setTextColor(Color.parseColor(MilkUtil.getTextColorLine(ms.getColorLine())));
		friday.setTextColor(Color.parseColor(MilkUtil.getTextColorLine(ms.getColorLine())));
		saturday.setTextColor(Color.BLUE);
		
		sengriTextView.setBackgroundColor(Color.parseColor(ms.getColorSengri()));
		sengriTextView.setTextColor(Color.parseColor(MilkUtil.getTextColorSelect(ms.getColorSengri())));
		
		gaimTextView.setBackgroundColor(Color.parseColor(ms.getColorGaim()));
		gaimTextView.setTextColor(Color.parseColor(MilkUtil.getTextColorSelect(ms.getColorGaim())));
		
		beranTextView.setBackgroundColor(Color.parseColor(ms.getColorBeran()));
		beranTextView.setTextColor(Color.parseColor(MilkUtil.getTextColorSelect(ms.getColorBeran())));
		
		sexTextView.setBackgroundColor(Color.parseColor(ms.getColorSex()));
		sexTextView.setTextColor(Color.parseColor(MilkUtil.getTextColorSelect(ms.getColorSex())));
		
		memoTextView.setBackgroundColor(Color.parseColor(ms.getColorMemo()));
		memoTextView.setTextColor(Color.parseColor(MilkUtil.getTextColorSelect(ms.getColorMemo())));
	}
}
